package cn.bdqn.crm.filter;


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class SysUserFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化");
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        HttpServletResponse response = (HttpServletResponse)resp;
        String token = request.getHeader("token");
        System.out.println("这次请求的token是:"+token);
        if(token!=null){
            chain.doFilter(request,response);
        }else{
          /*  PrintWriter out = response.getWriter();
            out.print("{\"retCode\":\"600\"}");
            out.close();*/
            request.getRequestDispatcher("/nologin").forward(request,response);
        }

    }

    @Override
    public void destroy() {

    }
}
